﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script src="../Js/jquery-1.9.1.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $.post("ASHXGetComment.ashx", function (data, status) {
                if (status != "success") {
                    $("#ulComment").append("<li>加载失败！</li>");
                    return;
                }
                var lines = data.split("$");
                for (var i = 0; i < lines.length; i++) {
                    var line = lines[i];
                    var fields = line.split("|");
                    var comment = $("<li><p>" + fields[0] + "</p><p><span>IP地址：" + fields[1] + "</span>&nbsp;&nbsp;&nbsp;&nbsp;<span>评论时间：" + fields[2] + " </span></p></li>");
                    $("#ulComment").append(comment);
                }
            })
        });

        $(function () {
            $("#BtnPost").click(function () {
                $.post("PostComment.ashx", { "msg": $("#TxtComment").val() },
                    function (data, status) {
                        if (status != "success") {
                            alert("发表评论失败,请重试！");
                            return;
                        }
                        if (data == "ok") {
                            var newComment = $("<li><p>" + $("#TxtComment").val() + "</p><p><span>IP地址：127.0.0.1 </span><span>评论时间：" + new Date() + " </span></p></li>");
                            $("#ulComment").append(newComment);
                            alert("评论发表成功！");
                        }
                        else if (data == "forbid") {
                            alert("评论请文明用语！");
                        }
                        else {
                            alert("发表评论时出错！");
                        }
                    });
            });
        });

    </script>
</head>
<body>
    <ul id="ulComment">
    </ul>
    <!-----AJAX----->
    <div>
        <p>
            <textarea id="TxtComment"></textarea>
        </p>
        <p>
            <input id="BtnPost" type="button" value="提交" />
        </p>
    </div>

</body>
</html>
